package com.senken.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.senken.mapper.ExpressMapper;
import com.senken.commons.entity.FidStateAndPage;
import com.senken.entity.Express;
import com.senken.service.IExpressService;
import com.baomidou.framework.service.impl.SuperServiceImpl;

/**
 *
 * Express 表数据服务层接口实现类
 *
 */
@Service
public class ExpressServiceImpl extends SuperServiceImpl<ExpressMapper, Express> implements IExpressService {

	@Autowired
	private ExpressMapper expressMapper;
	
	private static final int NUM=10;

	@Override
	public boolean addexpress(String expresswo,String sendname,String sendaddress,String receivename,String receivephone,String receiveaddress,String sendphone,String sendtime,String way){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Express express = new Express();
		express.setExpresswo(expresswo);
		express.setReceiveaddress(receiveaddress);
		express.setReceivename(receivename);
		express.setReceivephone(receivephone);
		express.setSendaddress(sendaddress);
		express.setSendname(sendname);
		express.setState(0);
		express.setSendphone(sendphone);
		express.setWay(way);
		try {
			express.setSendtime(sdf.parse(sendtime));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return this.insert(express);
	}
	
	@Override
	public List<Express> findExpress(int page,int state){
		FidStateAndPage fidStateAndPage = new FidStateAndPage();
		fidStateAndPage.setState(state);
		fidStateAndPage.setStart((page-1)*NUM);
		fidStateAndPage.setNum(NUM);
		return expressMapper.findExpress(fidStateAndPage);
	}	
	
	@Override
	public int counts(int state){
		return expressMapper.counts(state);
	}
	
	@Override
	public boolean updateState(int id,int state){
		Express express = this.selectById((long) id);
		express.setState(state);
		return this.updateById(express);
	}
	
	@Override
	public Express findone(String expresswo){
		Express express = new Express();
		express.setExpresswo(expresswo);
		return this.selectOne(express);
	}
}











